/**
 * 易码当先 <br>
 * Hadoop-mr <br>
 * cc.ic2c.hadoop.mr.patition <br>
 * AreaPatition.java <br>
 * @author Allister.Liu(刘继鹏) <br>
 * Email：laujip@163.com <br>
 * 时间：2017年11月14日-下午8:38:05 <br>
 * 2017Allister-版权所有 <br>
 */
package cc.ic2c.hadoop.mr.patition;

import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.mapreduce.Partitioner;

/**
 *   <br>
 * AreaPatition <br>
 * @author Allister.Liu(刘继鹏) <br>
 * Email：laujip@163.com <br>
 * 时间：2017年11月14日-下午8:38:05  <br>
 * @version 1.0.0
 * 
 */
public class AreaPatition<KEY, VALUE> extends Partitioner<KEY, VALUE>{
	
	private static Map<String, Integer> areaMap = new HashMap<String, Integer>();
	
	static
	{
		areaMap.put("135", 0);
		areaMap.put("136", 1);
		areaMap.put("137", 2);
		areaMap.put("138", 3);
		areaMap.put("139", 4);
	}

	/* (non-Javadoc)
	 * @see org.apache.hadoop.mapreduce.Partitioner#getPartition(java.lang.Object, java.lang.Object, int)
	 */
	@Override
	public int getPartition(KEY key, VALUE value, int numPartitions) {
		Integer provinceCode = areaMap.get(key.toString().substring(0, 3));
		return provinceCode == null ? 5 : provinceCode;
	}

}
